﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.MarketModel
{
    public partial class MMarketitemList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "MMarketitemList";
            }
        }
        #region 属性 (查询条件)


        protected string ItemName
        {
            get
            {
                return GetRequestValue<string>("ItemName", "");

            }
        }

        protected string SupplierName
        {
            get
            {
                return GetRequestValue<string>("SupplierName", "");
            }
        }
        /// <summary>
        /// 列表显示类型
        /// 0.显示全部
        /// 1.只显示价格,物料名称,供应商
        /// 2.只显示物料名称,库存
        /// </summary>
        protected int ShowListType
        {
            get
            {
                return GetRequestValue<int>("ShowListType",0);
            }
        }

        protected override string orderField
        {
            get
            {
                return (string.IsNullOrEmpty(base.orderField) ? " DisplayNum " : base.orderField);
            }
        }
        protected override string orderDirection
        {
            get
            {
                return base.orderDirection== "desc" ? "asc" : "desc";
                //return string.IsNullOrEmpty(base.orderDirection) ? "ASC" : base.orderDirection;
            }
        }

        protected override string SQLSort
        {
            get
            {
                return orderField + " " + orderDirection;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            this.AddLog(Permission.查看, GetSql());
        }

        protected void DataBind()
        {

            this.rpMenu.DataSource = MMarketItemController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }
        protected string GetSql()
        {
            string wheresql = "";



            string ItemCodeSQL = "";
            if (!string.IsNullOrEmpty(ItemName))
            {
                ItemCodeSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("ItemName", QueryOperatorsEnum.包含, ItemName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }

            string DOWNSQL = "";
            if (!string.IsNullOrEmpty(SupplierName))
            {
                DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("SupplierName", QueryOperatorsEnum.包含, SupplierName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }
            return wheresql;
        }
    }
}